<script setup lang="ts">
import { useI18n } from 'vue-i18n';

import config from '@/admin.config';
// @ts-ignore
import * as uniIdPagesStore from '@/uni_modules/uni-id-pages/common/store';
// @ts-ignore
import uniIdPageInit from '@/uni_modules/uni-id-pages/init.js';
import { onHide, onLaunch, onShow } from '@dcloudio/uni-app';

const { locale } = useI18n();
const authStore = useAuthStoreHook();

const init = () => {
	api.user.getUserInfo().then((data) => {
		authStore.setUserInfo(data!, { cover: true });
		uniIdPagesStore.mutations.setUserInfo(data, { cover: true });
	});
};

onPageNotFound(() => {
	uni.redirectTo({
		url: config.error['404'],
	});
});

onLaunch(async () => {
	await uniIdPageInit();

	if (authStore.hasLogin) {
		init();
	}

	uni.$on('uni-id-pages-login-success', () => {
		init();
	});
});

onUnload(() => {});

onShow(() => {
	// 监听浏览器尺寸变化
	window.addEventListener('resize', () => {
		// 获取html元素
		const htmlElement = document.documentElement;
		// 移除font-size属性
		htmlElement.style.removeProperty('font-size');
	});
});

onHide(() => {
	// 移除resize监听器
	window.removeEventListener('resize', () => {});
});
</script>

<style>
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
@import './styles/vxe-grid.css';

/* @import './styles/theme.css'; */
.uni-app--showtopwindow .uni-top-window {
	overflow: visible !important;
}
* {
	user-select: auto !important; /* 禁止选择 */
}
:root {
	--top-window-height: 40px !important;
	--left-window-width: 220px;
	--tab-height: 40px;
}
.app {
	font-size: 16px !important;
}

uni-left-window {
	flex-shrink: 0;
}
uni-main {
	overflow: auto;
}

.uni-left-window {
	height: calc(100vh - var(--top-window-height));
	overflow: auto;
}
</style>
